package com.rjpacket.chileme.app.models;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by WIN7 on 2015/3/23.
 */
public class Restaurant {

    /**
     * {
     * "deliver_spent": 0,
     * "is_favored": false,
     * "coupon_enabled": 0,
     * "invoice": 0,
     * "id": 195114,
     * "bookable": 1,
     * "flavors": "中式",
     * "num_rating_2": 0,
     * "icons": [
     * {
     * "index": 1,
     * "name": "在线支付满25减13，满50减23",
     * "color": "205, 34, 226",
     * "text": "在线支付满25减13，满50减23",
     * "id": "减",
     * "is_activity": true
     * },
     * {
     * "index": 2,
     * "name": "(不与其它活动同享)新用户下单立减15元",
     * "color": "83, 175, 39",
     * "text": "(不与其它活动同享)新用户下单立减15元",
     * "id": "首",
     * "is_activity": true
     * },
     * {
     * "index": 3,
     * "name": "可使用微信、支付宝、手机QQ进行在线支付",
     * "color": "238, 96, 37",
     * "text": "可使用微信、支付宝、手机QQ进行在线支付",
     * "id": "付",
     * "is_activity": false
     * }
     * ],
     * "online_payment": 1,
     * "latitude": 40.042647,
     * "tips": "月售227份 320元起送",
     * "activities": "1",
     * "upcoming_serving_time": 1427109974,
     * "description": "三只龙虾，鲜香麻辣，回味无穷",
     * "promotion_info": "1、本店推荐您在饿了么网上订餐，本店优先配送饿了么订单\n2、即日起，下单即送“麻辣花蛤”一份（原价38元）",
     * "phone": "18810801700",
     * "recent_food_popularity": 227,
     * "address": "北京市朝阳区北苑路六号院",
     * "num_rating_1": 0,
     * "num_rating_3": 0,
     * "status_description": "餐厅营业中",
     * "num_rating_5": 20,
     * "num_rating_4": 0,
     * "distance": "3.85km",
     * "min_deliver_amount": 320,
     * "name": "三只龙虾",
     * "invoice_min_amount": 0,
     * "is_brand": 0,
     * "longitude": 116.414807,
     * "image_url": "http://fuss10.elemecdn.com/d/7b/2c08d23fc9a3e437d50e88c588b24jpeg.jpeg?w=86&h=86",
     * "business_hour": "10:00:00-22:00:00",
     * "recent_order_number": 27,
     * "is_bookable": true,
     * "busy_level": 1,
     * "agent_fee": 0
     * },
     */

    //存放商铺中信息的图标
    private ArrayList<CateenInfoIcon> icons;

    private LinkedList<Restaurant> data;

    public ArrayList<CateenInfoIcon> getIcons() {
        return icons;
    }

    public void setIcons(ArrayList<CateenInfoIcon> icons) {
        this.icons = icons;
    }

    public LinkedList<Restaurant> getData() {
        return data;
    }

    public void setData(LinkedList<Restaurant> data) {
        this.data = data;
    }

    //解析
    public void parseJSON(JSONObject json) {
        if (json != null) {
            data = new LinkedList<Restaurant>();

            try {
                JSONArray jsonArray = json.getJSONArray("restaurant");
                for (int i = 0; i < jsonArray.length(); i++) {

                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    Restaurant res = new Restaurant();

                    res.setFlavors(jsonObject.getString("flavors"));
                    res.setId(jsonObject.getInt("id"));
                    res.setLatitude(jsonObject.getLong("latitude"));
                    res.setLongitude(jsonObject.getLong("longitude"));
                    res.setTips(jsonObject.getString("tips"));
                    res.setUpcoming_serving_time(jsonObject.getLong("upcoming_serving_time"));
                    res.setDescription(jsonObject.getString("description"));
                    res.setDistance(jsonObject.getString("distance"));
                    res.setPromotion_info(jsonObject.getString("promotion_info"));
                    res.setStatus_description(jsonObject.getString("status_description"));
                    res.setRecent_food_popularity(jsonObject.getInt("recent_food_popularity"));
                    res.setName(jsonObject.getString("name"));
                    res.setMin_deliver_amount(jsonObject.getInt("min_deliver_amount"));
                    res.setOnline_payment(jsonObject.getInt("online_payment"));
                    res.setAddress(jsonObject.getString("address"));
                    res.setPhone(jsonObject.getString("phone"));
                    res.setImage_url(jsonObject.getString("image_url"));
                    res.setBusiness_hour(jsonObject.getString("business_hour"));

                    //解析图标数组
                    JSONArray array = jsonObject.optJSONArray("icons");
                    icons = new ArrayList<CateenInfoIcon>();
                    for (int j = 0; j < array.length(); j++) {

                        CateenInfoIcon icon = new CateenInfoIcon();
                        JSONObject object = array.getJSONObject(j);

                        icon.setName(object.getString("name"));
                        icon.setColor(object.getString("color"));
                        icon.setText(object.getString("text"));
                        icon.setIndex(object.getInt("index"));
                        icon.setId(object.getString("id"));
                        icon.setIs_activity(object.getBoolean("is_activity"));

                        icons.add(icon);
                    }
                    res.setIcons(icons);
                    data.add(res);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    }

    private int id;
    //口味
    private String flavors;
    //纬度
    private float latitude;
    //精度
    private float longitude;
    //提示
    private String tips;
    //将要服务的时间
    private long upcoming_serving_time;
    //描述
    private String description;
    //距离
    private String distance;
    //促销信息
    private String promotion_info;
    //店铺营业状态
    private String status_description;
    //月售数量
    private int recent_food_popularity;
    //店铺名称
    private String name;
    //最低配送金额
    private int min_deliver_amount;
    //是否支持在线支付
    private int online_payment;
    //商铺地址
    private String address;
    //电话
    private String phone;
    //商铺商标
    private String image_url;
    //营业时间
    private String business_hour;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getFlavors() {
        return flavors;
    }

    public void setFlavors(String flavors) {
        this.flavors = flavors;
    }

    public float getLatitude() {
        return latitude;
    }

    public void setLatitude(float latitude) {
        this.latitude = latitude;
    }

    public float getLongitude() {
        return longitude;
    }

    public void setLongitude(float longitude) {
        this.longitude = longitude;
    }

    public String getTips() {
        return tips;
    }

    public void setTips(String tips) {
        this.tips = tips;
    }

    public long getUpcoming_serving_time() {
        return upcoming_serving_time;
    }

    public void setUpcoming_serving_time(long upcoming_serving_time) {
        this.upcoming_serving_time = upcoming_serving_time;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDistance() {
        return distance;
    }

    public void setDistance(String distance) {
        this.distance = distance;
    }

    public String getPromotion_info() {
        return promotion_info;
    }

    public void setPromotion_info(String promotion_info) {
        this.promotion_info = promotion_info;
    }

    public String getStatus_description() {
        return status_description;
    }

    public void setStatus_description(String status_description) {
        this.status_description = status_description;
    }

    public int getRecent_food_popularity() {
        return recent_food_popularity;
    }

    public void setRecent_food_popularity(int recent_food_popularity) {
        this.recent_food_popularity = recent_food_popularity;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getMin_deliver_amount() {
        return min_deliver_amount;
    }

    public void setMin_deliver_amount(int min_deliver_amount) {
        this.min_deliver_amount = min_deliver_amount;
    }

    public int getOnline_payment() {
        return online_payment;
    }

    public void setOnline_payment(int online_payment) {
        this.online_payment = online_payment;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getImage_url() {
        return image_url;
    }

    public void setImage_url(String image_url) {
        this.image_url = image_url;
    }

    public String getBusiness_hour() {
        return business_hour;
    }

    public void setBusiness_hour(String business_hour) {
        this.business_hour = business_hour;
    }
}
